package com.ruoyi.hr.service.impl.welfare.welfarepayment;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.domain.welfare.welfarecalculationconfig.CcdBenefititem;
import com.ruoyi.hr.mapper.welfare.welfarecalculationconfig.CcdBenefititemMapper;
import com.ruoyi.hr.mapper.welfare.welfarepayment.WelfarePaymentHistoryMapper;
import com.ruoyi.hr.service.welfare.welfarepayment.WelfarePaymentHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class WelfarePaymentHistoryServiceImpl implements WelfarePaymentHistoryService {

    @Autowired
    WelfarePaymentHistoryMapper welfarePaymentHistoryMapper;

    @Autowired
    private CcdBenefititemMapper ccdBenefititemMapper;

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findData(Map map,List<Authority> authorities,int isAdmin) {
        String name = map.get("name").toString();
        String badge = map.get("badge").toString();
        String term = map.get("term").toString();
        List<CcdBenefititem> ccdBenefititems = ccdBenefititemMapper.findPayBack();
        StringBuffer sql = new StringBuffer();
        for (CcdBenefititem ccdBenefititem : ccdBenefititems) {
            sql.append("(select Xvalue from CBENESUPPLY_ITEM_All  where SeqId = t.id and itemID = ");
            sql.append(ccdBenefititem.getId());
            sql.append(")" + ccdBenefititem.getTitle() + ",");
        }
        Map<String, Object> map1 = new HashMap<String, Object>();
        map1.put("sql", sql);
        map1.put("name", name);
        map1.put("badge", badge);
        map1.put("term", term);
        return welfarePaymentHistoryMapper.findData(map1,authorities,isAdmin);
    }
}
